class Stair {
    constructor() {
        this.init();
    }
}
$.extend(Stair.prototype, {
    init: function () {
        $(window).on("scroll", this.handlerMover.bind(this))
        this.stairs = $(".stairs")
        this.quote = $(".quote")
        this.qHeight = this.quote.offset().top
        this.sHeight = this.stairs.height();
        this.cHeight = document.documentElement.clientHeight || document.body.clientHeight;
        this.timer = null;
        this.handlerMover();
    },
    handlerMover: function () {
        this.scrollTop = document.documentElement.scrollTop || document.body.scrollTop
        this.changeColor(this.scrollTop);
        var target = parseInt(this.scrollTop + ((this.cHeight - this.sHeight) / 2) + 80)
        if (target >= 500 && target <= (this.qHeight - this.sHeight)) {
            this.stairs.css({ "display": "block" })
            this.stairsMove(target)
        } else if (target >= (this.qHeight - this.sHeight)) {
            clearInterval(this.timer)
            this.stairs.css({ "top": this.qHeight - this.sHeight })
        }
        else {
            this.stairs.css({ "display": "none" })
        }

    },
    stairsMove: function (target) {

        var offsetTop = this.stairs.offset().top
        clearInterval(this.timer)
        this.timer = setInterval($.proxy(function () {
            //如果大于就是 - 
            var speed = (offsetTop - target) / 20
            speed = speed > 0 ? Math.ceil(speed) : Math.floor(speed)
            offsetTop -= speed
            this.stairs.css({ top: offsetTop })
            if (target == this.stairs.offset().top) {
                clearInterval(this.timer)
            }
        }, this), 50)
    },
    changeColor: function (scrollTop) {
        // console.log(scrollTop)
        if (scrollTop > 500 && scrollTop < 930) {
            this.removeClass();
            this.stairs.children()[0].className += " turn"
        } else if (scrollTop >= 930 && scrollTop < 1400) {
            this.removeClass();
            this.stairs.children()[1].className += " turn"
        } else if (scrollTop >= 1400 && scrollTop < 2100) {
            this.removeClass();
            this.stairs.children()[2].className += " turn"
        } else if (scrollTop >= 2100 && scrollTop < 2700) {
            this.removeClass();
            this.stairs.children()[3].className += " turn"
        } else if (scrollTop >= 2700 && scrollTop < 3100) {
            this.removeClass();
            this.stairs.children()[4].className += " turn"
        }else if(scrollTop >= 3100){
            this.removeClass();
            this.stairs.children()[5].className += " turn"
        }

    },
    removeClass: function () {
        this.stairs.children().each(function (index, item) {
            $(item).removeClass("turn")
        })
    }
})

var stair = new Stair()
export { stair }